#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target)
    {
        int n = matrix.size(), m = matrix[0].size();
        int line = 0, col = m - 1;
        while (line >= 0 && line < n && col >= 0 && col < m)
        {
            if (matrix[line][col] > target)
            {
                --col;
            }
            else if (matrix[line][col] < target)
            {
                ++line;
            }
            else
            {
                return true;
            }
        }
        return false;
    }
};